home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Pyramid / Source / TransformController.m < prev   
Text File  |  1993-09-15  |  2KB  |  96 lines

  1. /*    TransformController.m - Determine current transformation.
  2.  *    Copyright (C) 1993 Corona Design, Inc. All rights reserved.
  3.  *
  4.  *    Abstract
  5.  *        Encapsulates the interface for specifying viewing angle. This is
  6.  *        done via CircularSliders specifying Latitude and Longitude.
  7.  *
  8.  *    RCS path: 
  9.  *        $Source: /Users/pkron/Projects/voxel/Pyramid/RCS/TransformController.m,v $
  10.  *    Modified: $Date: 93/09/15 12:35:26 $ by $Author: pkron $
  11.  *    Current State: $State: Exp $ locked by $Locker:  $
  12.  */
  13.  
  14. #import    "TransformController.h"
  15. #import    "standard.h"
  16.  
  17.                                 // add some trigononmetry to standard Controls
  18. @implementation Control( radians)
  19.  
  20. #define    PI                3.1415926536
  21. #define    RAD(degrees)    ((degrees)/180.*PI)
  22.  
  23. - (float)radiansValue
  24.     {
  25.     return( RAD( [self floatValue]));
  26.     }
  27.     
  28.  
  29. - (float)cosValue
  30.     {
  31.     return( cos( [self radiansValue]));
  32.     }
  33.     
  34.  
  35. - (float)sinValue
  36.     {
  37.     return( sin( [self radiansValue]));
  38.     }
  39.     
  40.  
  41. @end
  42.  
  43. @implementation TransformController
  44.  
  45. - init
  46.     {
  47.     [super init];
  48.     transform = allocIdentity();
  49.     return( self);
  50.     }
  51.  
  52.     
  53. #define    DISTANCE        ([distance floatValue]+1)
  54.  
  55. - (MATRIX)transform
  56.     {
  57.     POINT    aPoint;
  58.     POINT    up;
  59.     float    cosLatitude = [latitude  cosValue];
  60.  
  61.                                 // compute normal from latitude/longitude
  62.                                 // vector has length 1 and is normal to
  63.                                 // viewing plane
  64.     aPoint[2] = [latitude  sinValue];
  65.     aPoint[0] = cosLatitude * [longitude cosValue];
  66.     aPoint[1] = cosLatitude * [longitude sinValue];
  67.     aPoint[3] = 0;
  68.  
  69.                                 // define UP. Note it must change as the
  70.                                 // viewing angle gets upside-down        
  71.     up[0] = 0;
  72.     up[1] = 0;
  73.     up[2] = cosLatitude GE 0 ? 1 : -1;
  74.     up[3] = 0;
  75.  
  76.                                 // create a new matrix with this setting
  77.     freeMatrix( transform);
  78.     transform = allocIdentity();
  79.     orient( transform, &aPoint, &up);
  80.     viewDistance( transform, DISTANCE);
  81.     
  82.     return( transform);
  83.     }
  84.     
  85.  
  86. @end
  87.  
  88. #ifdef    _LOG
  89. /*
  90.  *    $Log:    TransformController.m,v $
  91. Revision 1.1  93/09/15  12:35:26  pkron
  92. Created.
  93.  
  94.  */
  95. #endif        
  96.